!function () {
	var init = function () {
		Event();
		sliderFun();
	};
	//首页头部滑上显示
	var Event = function () {
		$('.header-btn').on('mouseover', function () { $('.header-btn').find('div').show() });
		$('.header-btn').on('mouseleave', function () { $('.header-btn').find('div').hide() });
		$('.header-list').on('mouseover', function () { $('.header-list').find('div').show() });
		$('.header-list').on('mouseleave', function () { $('.header-list').find('div').hide() });
		$('.mode').on('mouseover', function () { $('.mode').find('div').show() });
		$('.mode').on('mouseleave', function () { $('.mode').find('div').hide() });
	};
	//图片轮播
	function sliderFun() {
		var ul = $('.carousel ul'),
			liwidth = ul.find('li').width(),
			lilen = ul.find('li').length,
			timer;
		ul.css('width', liwidth * lilen);
		$('.icon-left').on('click', function () {
			ul.prepend(ul.find('li:last'))
				.css('margin-left', -liwidth)
				.animate({ 'margin-left': 0 }, 1000)
		})
		$('.icon-right').on('click', function () {
			ul.animate({ 'margin-left': -liwidth }, 2000, function () {
				ul.append(ul.find('li:first'))
					.css('margin-left', 0)
			})
		})
		aplay()
		function aplay() {
			timer = setInterval(function () {
				$('.icon-right').trigger('click')
			}, 3000)
		}
		ul.mouseenter(function () {
			clearInterval(timer)
		})
		ul.mouseleave(function () {
			aplay()
		})
	}

	$(function () {
		//渲染宣传彩页模块
		$.ajax({
			type: 'get',
			url: 'http://localhost/ryw/api.php/records/rywshops?transform=1&filter=firstid,eq,1',
			success: function (data) {
				// console.log(data.rywshops)
				var dataArr = [], htmlArr = [];
				for (var i = 0; i < 6; i++) {
					dataArr.push(data.records[i])
				}
				for (var i = 0; i < dataArr.length; i++) {
					htmlArr.push(
						`<li>
							<a href="javascript:;">
								<p class="p1"><img style="width:80%" src="../img/a8.jpg" alt=""></p>
								<p class="p2">${dataArr[i].title}</p>
								<p style="color:red;">￥${dataArr[i].price}元<span class="butn1_2" data-index="${dataArr[i].id}"></span></p>
							</a>
						</li>`
					)
				}
				$('.pro_list ul').html(htmlArr.join(''))

			}
		})
		//显示立即购买
		$('.pro_list ul').on('mouseenter','li', function () {
			var $this = $(this).index();
			$('.butn1_2').eq($this).stop().animate({ 'margin-top': '10px' }, 200)
			// $('.butn1_2').css('margin-top','10px')
		})
		//隐藏立即购买
		$('.pro_list ul').on('mouseleave','li', function () {
			var $this = $(this).index();
			$('.butn1_2').eq($this).stop().animate({ 'margin-top': '50px' }, 200)
		})
		//点击立即购买
		$('.pro_list ul').on('click','.butn1_2',function(){
			var uid = this.getAttribute('data-index');
			localStorage.setItem("zxwx-detailID",uid)
			window.location.href = '../html/details.html';
		})
	})

	init();
}();